/*
 * 
 * Copyright 2011 visual-analysis-of-cancer.
 * This file is part of visual-analysis-of-cancer.
 * 
 * visual-analysis-of-cancer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * visual-analysis-of-cancer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * visual-analysis-of-cancer:
 * An tool to analye the WHO and GLOBOCAN cancer data.
 * http://code.google.com/p/visual-analysis-of-cancer/
 * 
 * 
 * 
 * Authors: Erik Sniegula, Johannes Dahlke
 * 
 * Module:  Programming in Processing for Visual Analytics
 * Group:   20
 * 
 * Created: Aug. 2011
 * Version: 1.0
 *
 */
 




package de.fuberlin.processing.who.cancer.utils;

import java.util.Collection;
import java.util.Vector;

import javax.xml.stream.events.Characters;


public class Typecast {

	public static Collection<Integer> convertFloatsToIntegers(
			Collection<Float> floatValues) {
		Vector<Integer> integerValues = new Vector<Integer>();
		if ( Test.isAssigned( floatValues)) {
			for ( Float f : floatValues) {
				integerValues.add( f.intValue());
			}
			return integerValues;
		}
		return null;
	}


	public static Collection<Character> convertIntegersToCharacters(
			Collection<Integer> integerValues) {
		Vector<Character> charValues = new Vector<Character>();
		if ( Test.isAssigned( integerValues)) {
			for ( Integer i : integerValues) {
				charValues.add( String.format( "%c", (char) i.intValue()).charAt( 0));
			}
			return charValues;
		}
		return null;
	}


	public static Collection<Integer> convertCharactersToIntegers(
			Collection<Character> charValues) {
		Vector<Integer> integerValues = new Vector<Integer>();
		if ( Test.isAssigned( charValues)) {
			for ( Character c : charValues) {
				integerValues.add( (int) c);
			}
			return integerValues;
		}
		return null;
	}


	public static String convertIntegersToCommaSeparatedString(
			Collection<Integer> intValues) {
		String csvSubregions = "";
		if ( Test.isAssigned( intValues)) {
			for ( int value : intValues) {
				if ( csvSubregions.length() != 0)
					csvSubregions += ',';
				csvSubregions += String.format( "\"%d\"", value);
			}
		}
		return csvSubregions;
	}


	public static String convertCharactersToCommaSeparatedString(
			Collection<Character> charValues) {
		String csvSubregions = "";
		if ( Test.isAssigned( charValues)) {
			for ( char c : charValues) {
				if ( csvSubregions.length() != 0)
					csvSubregions += ',';
				csvSubregions += String.format( "\"%c\"", c);
			}
		}
		return csvSubregions;
	}

}
